package com.qf.bank.funprovider.controller;



import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.qf.bank.funapi.po.Fun;
import com.qf.bank.funapi.vo.FunVo;
import com.qf.bank.funprovider.service.FunService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author lwf
 * @since 2019-12-05
 */
@RestController
public class FunController {

    @Autowired FunService funService;
    /**
     * 分页查询
     */
    @RequestMapping(value = "", method = RequestMethod.GET)
    public IPage<Fun> page(@RequestBody FunVo funVo) {
        return funService.pageWithCondition(funVo);
    }

    /**
     * 根据主要分类查询
     * @param
     * @return
     */
//    @RequestMapping(value = "/type/{funType}",method = RequestMethod.GET)
//    public List<Fun> getFunByType(@PathVariable("funType")String funType){
//        List<Fun> byType = funService.getFunByType(funType);
//        return byType;
//    }

       /**
     * 根据id查询
     * @param
     * @return
     */
    @RequestMapping(value = "/{funId}",method = RequestMethod.GET)
    public Fun getById(@PathVariable("funId")int funId){
        Fun byId = funService.getById(funId);
        return byId;
    }
/*    *//**
     * 根据id查询
     * @param
     * @return
     *//*
    @RequestMapping(value = "/",method = RequestMethod.GET)
    public List<Fun> getfunByObject(Fun fun){
//        Wrappers.<Users>lambdaQuery().eq(Users::getUserPhone, users.getUserPhone()).eq(Users::getUserPassword, users.getUserPassword())
//        Object pa=null;
//        Wrappers.<Fun>lambdaQuery().eq(Fun::pa, users.getUserPhone())
//        Map<String,Fun> map=new HashMap<String,Fun>()
        List<Fun> byId = funService.list(Wrappers.<Fun>lambdaQuery().eq(Fun::getFunTips, fun.getFunTips()).eq(Fun::getFunId,));
        return byId;
    }*/

    /**
     * 根据id删除
     * @param funId
     * @return
     */
    @RequestMapping(value = "/{funId}",method = RequestMethod.DELETE)
    public Boolean deleteById(@PathVariable("funId")int funId){
        boolean removeById = funService.removeById(funId);
        return removeById;
    }

    /**
     * 添加一个功能
     * @param fun
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.POST)
    public Boolean getinsert(@RequestBody Fun fun){
        boolean saveOrUpdate = funService.saveOrUpdate(fun);
        return saveOrUpdate;
    }

    /**
     * 修改功能
     * @param fun
     * @return
     */
    @RequestMapping(value = "/",method = RequestMethod.PUT)
    public Boolean updateById(@RequestBody Fun fun){
        boolean updateById = funService.updateById(fun);
        return updateById;
    }



}
